package com.speechb.modules.shiro.matcher;

import com.speechb.common.codec.Md5Utils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 用户密码校验
 * @author : llj
 * @version :2.1.0
 * @date : 2019/10/3 7:46
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {
    private final static Logger logger = LoggerFactory.getLogger(CustomCredentialsMatcher.class);
    @Override
    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo info) {
        // 用户输入
        UsernamePasswordToken token = (UsernamePasswordToken)authenticationToken;
        String userPwd = Md5Utils.md5(String.valueOf(token.getPassword()),2);
        // 后台数据库获取
        Object accountCredentials = getCredentials(info);
        return equals(userPwd,accountCredentials);
    }
}
